home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / userconf / userconf.c < prev    next >
C/C++ Source or Header  |  1996-07-20  |  4KB  |  150 lines

  1. #pragma implementation
  2. #include <unistd.h>
  3. #include "../xconf/xconf.h"
  4. #include "internal.h"
  5. #include "userconf.h"
  6. #include "../paths.h"
  7. #include "userconf.m"
  8.  
  9. static USERCONF_HELP_FILE help_intro ("intro");
  10.  
  11. void userconf_edit()
  12. {
  13.     /* #Specification: userconf / principal
  14.         The userconf program allows you to edit/create/delete user
  15.         accounts and groups.
  16.     */
  17.     int choice=0;
  18.     while (1){
  19.         static const char *user_accounts = MSG_U(M_USER,"user accounts");
  20.         static const char *groupe_def = MSG_U(M_GROUPDEF,"group definitions");
  21.         static const char *users_pass = MSG_U(M_UPASS,"users password");
  22.         static const char *root_pass = MSG_U(M_ROOTPASS,"root password");
  23.         static const char *std_ppp = MSG_U(M_PPP,"PPP account via normal login");
  24.         static const char *pap_ppp = MSG_U(M_PPPPAP,"PPP account via PAP authentication");
  25.         static const char *chap_ppp = MSG_U(M_PPPCHAP,"PPP account via CHAP authentication");
  26.         static const char *std_slip = MSG_U(M_SLIP,"SLIP account via normal login");
  27.         static const char *uucp_account = MSG_U(M_UUCP,"UUCP account");
  28.         static const char *pop_accounts = MSG_U(M_POP,"POP accounts (mail only)");
  29.         static const char *passwd_policies = MSG_U(M_POLICIES,"Password setting policies");
  30.         static const char *menuopt[]={
  31.             MSG_U(M_ECREATE,"Edit/Create"),    user_accounts,
  32.             " ",        groupe_def,
  33.             MSG_U(M_CHANGE,"Change"),    users_pass,
  34.             " ",        root_pass,
  35.             "-",        "Special accounts",
  36.             MSG_R(M_ECREATE),    std_ppp,
  37.             " ",        pap_ppp,
  38.             " ",        chap_ppp,
  39.             " ",        std_slip,
  40.             " ",        uucp_account,
  41.             " ",        pop_accounts,
  42.             "-",        "",
  43.             MSG_U(M_EDIT,"Edit"),        passwd_policies,
  44.             NULL
  45.         };
  46.         MENU_STATUS code = xconf_menu (
  47.             MSG_U(T_UCONF,"User account configurator")
  48.             ,MSG_U(I_UCONFINTRO
  49.              ,"This package allows you to add/delete\n"
  50.              "and manage user accounts\n")
  51.             ,help_intro
  52.             ,menuopt,choice);
  53.         if (code == MENU_QUIT || code == MENU_ESCAPE){
  54.             break;
  55.         }else{
  56.             const char *key = menuopt[choice*2+1];
  57.             if (key == user_accounts){
  58.                 users_edit(NULL);
  59.             }else if (key == pop_accounts){
  60.                 USER *like;
  61.                 if (special_init (POP_GROUP,like) != -1){
  62.                     users_edit(like);
  63.                 }
  64.                 delete like;
  65.             }else if (key == std_ppp){
  66.                 USER *like;
  67.                 if (special_init (PPP_GROUP,like) != -1){
  68.                     users_edit(like);
  69.                 }
  70.                 delete like;
  71.             }else if (key == std_slip){
  72.                 USER *like;
  73.                 if (special_init (SLIP_GROUP,like) != -1){
  74.                     users_edit(like);
  75.                 }
  76.                 delete like;
  77.             }else if (key == uucp_account){
  78.                 USER *like;
  79.                 if (special_init (UUCP_GROUP,like) != -1){
  80.                     users_edit(like);
  81.                 }
  82.                 delete like;
  83.             }else if (key == pap_ppp){
  84.             }else if (key == chap_ppp){
  85.             }else if (key == groupe_def){
  86.                 groups_edit();
  87.             }else if (key == passwd_policies){
  88.                 PASSWD_VALID vl;
  89.                 vl.edit();
  90.             }else if (perm_rootaccess(
  91.                 MSG_U(P_CHGPASS,"change users password"))){
  92.                 USERS users;
  93.                 int save_ok = -1;
  94.                 if (key == users_pass){
  95.                     save_ok = users.editpass(NULL);
  96.                 }else if (key == root_pass){
  97.                     USER *root = users.getitem("root");
  98.                     SHADOW *shadow = users.getshadow(root);
  99.                     save_ok = root->editpass(0,shadow);
  100.                 }
  101.                 if (save_ok != -1) users.write();
  102.             }
  103.         }
  104.     }
  105. }
  106. /*
  107.     Edit the password of the current user or one specific user
  108. */
  109. int userconf_passwd (int argc, char *argv[])
  110. {
  111.     USERS users;
  112.     int save_ok = -1;
  113.     if (argc == 1){
  114.         USER *usr = users.getfromuid(getuid());
  115.         SHADOW *shadow = users.getshadow (usr);
  116.         if (usr == NULL){
  117.             xconf_error (
  118.                 MSG_U(E_NOUID,"Can't locate entry for uid %d\n"
  119.                 "in %s"),getuid(),ETC_PASSWD);
  120.         }else{
  121.             if (isatty(0) && isatty(1)){
  122.                 dialog_clear();
  123.                 save_ok = usr->edithispass(shadow);
  124.             }else{
  125.                 save_ok = usr->edithispass_notty(shadow);
  126.             }
  127.             if (save_ok != -1) perm_forceok();    // This let the write
  128.                                                 // succeed
  129.         }
  130.     }else if (argc == 2){
  131.         USER *usr = users.getitem(argv[1]);
  132.         if (usr == NULL){
  133.             xconf_error (MSG_U(E_UNKNOWNUSER,"Unknown user %s\n"),argv[1]);
  134.         }else if (perm_rootaccess(MSG_R(P_CHGPASS))){
  135.             SHADOW *shadow = users.getshadow (usr);
  136.             dialog_clear();
  137.             save_ok = usr->editpass(1,shadow);
  138.         }
  139.     }
  140.     if (save_ok != -1) users.write();
  141.     return 0;
  142. }
  143.  
  144. int userconf_main (int , char *[])
  145. {
  146.     userconf_edit();
  147.     return 0;
  148. }
  149.  
  150.